/*
  Programa Wifis, 2010-2011
  Autor: Nilhcraiv

This file is part of Wifis.

    Wifis is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Wifis is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Wifis.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "displayinformation.h"

displayInformation::displayInformation(QVector <QString> *networks)
{
    model = new QStandardItemModel(0,10);
    model->setHeaderData(0,Qt::Horizontal," SSID ");
    model->setHeaderData(1,Qt::Horizontal," Tipo de Red ");
    model->setHeaderData(2,Qt::Horizontal," Autentication ");
    model->setHeaderData(3,Qt::Horizontal," Cifrado ");
    model->setHeaderData(4,Qt::Horizontal," BSSID ");
    model->setHeaderData(5,Qt::Horizontal," Señal ");
    model->setHeaderData(6,Qt::Horizontal," Tipo Radio ");
    model->setHeaderData(7,Qt::Horizontal," Canal ");
    model->setHeaderData(8,Qt::Horizontal," Vulnerable ");
    model->setHeaderData(9,Qt::Horizontal," Contraseña ");

    saveNetworks = networks;
}

//Private functions

QStandardItemModel* displayInformation::createModel(QVector <QString> vectorNetworks)
{
    int numItem=0;
    bool checkTable=true;

    this->deleteItemsFromModel();

    for(int j=0;j<(vectorNetworks.size()/10);j++)//rows,lo divido entre 10, xq tengo 10 paramentros
    {
        for(int i=0;i<10;i++)//colums
        {
            model->setItem(j,i, crearElemento(vectorNetworks[numItem],checkTable));//row,colum,item
            numItem++;
            checkTable = false;
        }//for i
        checkTable = true;
    }//for j

    return model;
}//createModel

QStandardItem* displayInformation::crearElemento(QString nombre, bool checkTable)
{
    QStandardItem *elemento = new QStandardItem(nombre);

    if(checkTable)
    {
        elemento->setCheckable(true);
        elemento->setEditable(false);
        //elemento->setCheckState(Qt::Checked);
    }else
    {
        elemento->setEditable(false);
    }//else

    return elemento;
}//crearElemento

bool displayInformation::isCheck(int numElement,QStandardItemModel *model)
{
    if(model->item(numElement)->checkState() == Qt::Checked)
    {
        return true;
    }//if

    return false;
}//ifcheektable


QStandardItemModel* displayInformation::getModel()
{
    return createModel(*saveNetworks);
}//modelo
